Skip to content

Conversation

@reosfire
Copy link
Contributor

@reosfire reosfire commented May 1, 2025

It seems for me like this change should make shaders more readable and easier to write

@soywiz soywiz requested a review from Copilot May 2, 2025 07:19
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors shader code to use inline TEMP initialization with initial values, aiming to make the shader code more readable and easier to write. Key changes include:

  • Replacing separate TEMP declarations and SET calls with inline initialization.
  • Updating variable naming to a lower-case style in shader fragments.
  • Adding explicit type information to math function calls in the shader DSL.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
korge/src/korlibs/korge/view/filter/DitheringFilter.kt Updated index initialization and shader variable naming.
korge/src/korlibs/korge/view/fast/FSprites.kt Adjusted baseSize computation and refined TEMP initialization for trigonometric values.
korge/src/korlibs/korge/render/RenderContext2DExt.kt Replaced SET calls with inline TEMP initialization for shader variables.
korge-core/src/korlibs/korge/render/SDFShaders.kt Inlined TEMP initializations in SDF functions for clarity.
korge-core/src/korlibs/graphics/shader/shaders.kt Updated math functions and introduced a new TEMP overload with explicit type information.
Comments suppressed due to low confidence (3)

korge/src/korlibs/korge/view/filter/DitheringFilter.kt:41

  • Using inline initialization via TEMP improves clarity; please verify that the order of evaluation remains consistent with previous behavior.
val index = TEMP(float(x + y * width.lit))

korge-core/src/korlibs/graphics/shader/shaders.kt:493

  • Providing explicit type information in math functions like sin, cos, and tan enhances type safety; please confirm that all downstream usages align with this update.
fun sin(angle: Operand): Operand = Func("sin", angle, type = angle.type)

korge-core/src/korlibs/graphics/shader/shaders.kt:769

  • The new TEMP overload for inline initialization improves code readability; please verify its consistent adoption throughout the shader code.
fun TEMP(initialValue: Operand): Temp {

fun atan(y_over_x: Operand): Operand = Func("atan", y_over_x)
fun asin(x: Operand): Operand = Func("asin", x, type = x.type)
fun acos(x: Operand): Operand = Func("acos", x, type = x.type)
fun atan(yOverX: Operand): Operand = Func("atan", yOverX)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing type = yOverX.type?

Copy link
Contributor

@soywiz soywiz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. But likely atan is missing the type = as the other functions

@reosfire reosfire force-pushed the temp-with-initial-value branch from 2c7acdb to 48ab7bc Compare May 5, 2025 14:10
@soywiz soywiz changed the title TEMP with initial value TEMP with initial value and provide default types for shader functions May 5, 2025
@soywiz soywiz merged commit 3dbd36a into korlibs:main May 5, 2025
6 checks passed
@soywiz
Copy link
Contributor

soywiz commented May 5, 2025

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants